<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
request.setCharacterEncoding("UTF-8");
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <base href="<%=basePath%>">
<title>合作伙伴配置</title>

<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
	history.forward();
	$(document).ready(function() {
		isReadyIframe();
		queryChannelInfo(1);
	});	
	
	function isReadyIframe(){
		var iframe = $(window.parent.document).find("#iframe").length;
		if(iframe==0){
			window.location.href="<%=basePath%>index.jsp";
		}
	}
	
	
	//保留
	//点击“查询”
	function queryChannelInfo(pageIndex){
		var channelName = $("#channelNameInput").val();
		var channelCode = $.trim($("#channelCodeInput").val());
		
		$.openLoading();
		//按照条件执行查询操作
		$.ajax({
			url : "<%=path%>/channelManage/queryByCriteria?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:{
				channelName:channelName,
				channelCode:channelCode,
				pageIndex:pageIndex
			},
			dataType:'json',
			success:function(channelInfoPage){
				$.closeLoading();
				
				if($.validate(channelInfoPage))  return;
				
				if(null != channelInfoPage){
					var channelSort = "";
					<c:forEach items="${channelSortList}" var="channelSort" varStatus="member">
						<c:choose>
							<c:when test="${member.first}">
								channelSort += "[{'${channelSort.code}':'${channelSort.codeName}'};"; 
							</c:when>
							<c:when test="${member.last}">
								channelSort += "{'${channelSort.code}':'${channelSort.codeName}'}]";
							</c:when>
							<c:otherwise>
								channelSort += "{'${channelSort.code}':'${channelSort.codeName}'};";
							</c:otherwise>
						</c:choose>
					</c:forEach>
					var buttonStr = "<a href='javascript:void(0)' onClick='viewChannelAttribute(this);return false'>编辑</a>";
					var fieldNames = "CHANNEL_CODE,CHANNEL_NAME,CHANNEL_SORT?"+channelSort+",CHANNEL_SORT@TDH,DEPT_CNAME,DEPT_CODE@TDH,TRANS_TYPE?[{'1':'界面出单'};{'2':'系统对接'}],TRANS_TYPE@TDH,IS_USERANDPW_VALIDATE@TDH,IS_IP_VALIDATE@TDH,IS_RSA_ENCRYPT@TDH,IS_THIRD_PLAN@TDH,ESTIMATE_AMOUT@TDH,ESTIMATE_DES@TDH,TBR_EMAIL@TDH,CHANNEL_SORT@TDH,CHANNEL_FLAG@TDH";					
					var tableContent = creatTable1(fieldNames,channelInfoPage,null,buttonStr);
					var tableObj = $("#channelInfoTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(pageIndex,6,channelInfoPage.maxPage,"1");
					var pageDIV = $("#channelInfoPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
				}
			}
		});
	}
	
	//点击“保存/更新”,flag='save'保存,flag='update'更新
	function saveOrUpdateChannelAttribute(flag){
//		var deptCname = $('#deptCnameTr').val();
		var deptCode = $('#deptCode').val();
		//合作伙伴代码
		var channelCode = $('#channelCode').val();
		//支付结果回调地址
		var payBackURL = $('#payBackURL').val();
		//核保结果回调地址
		var uwBackURL = $('#uwBackURL').val();
		//电子发票回调地址
		var einvoiceBackURL = $('#einvoiceBackURL').val();
		//新意健险批改回写地址
		var corrBackURL = $('#corrBackURL').val();
		//财险批改回写地址
		var ncorrBackURL = $('#ncorrBackURL').val();
		//体检机构；0代表善诊，1代表通用体检机构 
		var physicalExaminationDept = $('#physicalExaminationDept').val();
		//是否接口传入保单号
		var afferentPolno = $('#afferentPolno').val(); 
		//体检机构地址
		var physicalExaminationURL = $('#physicalExaminationURL').val();
		//请求参数
		var params = {flag:flag,channelCode:channelCode,deptCode:deptCode,payBackURL:payBackURL,uwBackURL:uwBackURL,einvoiceBackURL:einvoiceBackURL,corrBackURL:corrBackURL,ncorrBackURL:ncorrBackURL,physicalExaminationDept:physicalExaminationDept,afferentPolno:afferentPolno,physicalExaminationURL:physicalExaminationURL};
		console.log(params);
		$.ajax({
			url : "<%=path%>/channelManage/saveOrUpdateChannelAttribute",
			type : 'POST',
			async : true,
			data:params,
			dataType:'json',
			success:function(obj){
				$.closeLoading();
				if($.validate(obj))  return;
				closeSaveOrUpdateDiv();
				queryChannelInfo(1);
			}
		});
	}
	
	//保留 loadGatewayChannelInfo
	//点击“编辑”（channelInfo）
	function viewChannelAttribute(channelAttribute){
		var tempTr = $(channelAttribute).parent().parent()[0];
		var channelCode= tempTr.childNodes[0].innerHTML;
		var channelName = tempTr.childNodes[1].innerHTML;
		var channelSortName = tempTr.childNodes[2].innerHTML;
		var channelSort = tempTr.childNodes[3].innerHTML;
		var deptCname = tempTr.childNodes[4].innerHTML;
		var deptCode = tempTr.childNodes[5].innerHTML;
//			var transType = tempTr.childNodes[6].innerHTML;
//			var transUser = tempTr.childNodes[7].innerHTML;
//			var transIp = tempTr.childNodes[8].innerHTML;
//			var transRsa = tempTr.childNodes[9].innerHTML;
//			var is_Async = tempTr.childNodes[10].innerHTML;
//			var channelSort=tempTr.childNodes[18].innerHTML;
//			var channelflag=tempTr.childNodes[19].innerHTML;
		$.ajax({
			url : "<%=path%>/channelManage/queryChannelInfoByChannelCode",
			type : 'POST',
			async : true,
			data:{channelCode:channelCode},
			dataType:'json',
			success:function(GatewayChannelInfo){
				$.closeLoading();
				if($.validate(GatewayChannelInfo))  return;
				
				if(GatewayChannelInfo != null && channelSort == 11){
					//显示体检机构地址,隐藏其它 tr 
					$('#physicalExaminationURLTr').show();
					$('#payBackURLTr').hide();
					$('#uwBackURLTr').hide();
					$('#einvoiceBackURLTr').hide();
					$('#corrBackURLTr').hide();
					$('#ncorrBackURLTr').hide();
					$('#physicalExaminationDeptTr').hide();
					$('#afferentPolnoTr').hide();
					//体检机构地址
					if(GatewayChannelInfo.physicalExaminationURL) $('#physicalExaminationURL').val(GatewayChannelInfo.physicalExaminationURL);
				}else if(GatewayChannelInfo != null){
					//隐藏体检机构地址,显示其它block
					$('#physicalExaminationURLTr').hide();//体检机构地址
					$('#payBackURLTr').show();
					$('#uwBackURLTr').show();
					$('#einvoiceBackURLTr').show();
					$('#corrBackURLTr').show();
					$('#ncorrBackURLTr').show();
					$('#physicalExaminationDeptTr').show();
					$('#afferentPolnoTr').show();
					//支付结果回调地址
					if(GatewayChannelInfo.payBackURL) $('#payBackURL').val(GatewayChannelInfo.payBackURL);
					//核保结果回调地址
					if(GatewayChannelInfo.uwBackURL) $('#uwBackURL').val(GatewayChannelInfo.uwBackURL);
					//电子发票回调地址
					if(GatewayChannelInfo.einvoiceBackURL) $('#einvoiceBackURL').val(GatewayChannelInfo.einvoiceBackURL);
					//新意健险批改回写地址
					if(GatewayChannelInfo.corrBackURL) $('#corrBackURL').val(GatewayChannelInfo.corrBackURL);
					//财险批改回写地址
					if(GatewayChannelInfo.ncorrBackURL) $('#ncorrBackURL').val(GatewayChannelInfo.ncorrBackURL);
					//体检机构；0代表善诊，1代表通用体检机构 
					if(GatewayChannelInfo.physicalExaminationDept) $('#physicalExaminationDept').val(GatewayChannelInfo.physicalExaminationDept);
					//是否接口传入保单号
					if(GatewayChannelInfo.afferentPolno) $('#afferentPolno').val(GatewayChannelInfo.afferentPolno);
				}
				$('#channelCode').val(channelCode);
				$('#channelName').val(channelName);
				$('#channelSort').val(channelSortName);
				$('#deptCname').val(deptCname);
				$('#deptCode').val(deptCode);
				$("#editChanelAttributeDiv").OpenDiv();
			}
		});
		
	}
	
	//关闭弹出层,清空已查询的数据
	function closeSaveOrUpdateDiv(){
		$("#editChanelAttributeDiv").CloseDiv();
		//合作伙伴代码
		$('#channelCode').val("");
		//合作伙伴名称
		$('#channelName').val("");
		//合作伙伴分类
		$('#channelSort').val("");
		//所属机构
		$('#deptCname').val("");
		//所属机构代码
		$('#deptCode').val("");
		//支付结果回调地址
		$('#payBackURL').val("");
		//核保结果回调地址
		$('#uwBackURL').val("");
		//电子发票回调地址
		$('#einvoiceBackURL').val("");
		//新意健险批改回写地址
		$('#corrBackURL').val("");
		//财险批改回写地址
		$('#ncorrBackURL').val("");
		//体检机构；0代表善诊，1代表通用体检机构 
		$('#physicalExaminationDept').val("");
		//是否接口传入保单号
		$('#afferentPolno').val("");
		//体检机构地址
		$('#physicalExaminationURL').val("");
	}

</script>
  </head> 
  <body>
  
 	 <div class="current">
           <table class="current_table_1">
             <tbody>
              	<tr class="f2">
	                <td><img src="./images/current_1.jpg"></td>
	                <td class="current_table_1_td">
	                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
	                  <span style=" color:#136bab; ">合作伙伴管理
	                  	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>合作伙伴属性
	                  </span>
                  	</td>
                 	<td><img src="./images/current_3.jpg"></td>
              	</tr>
           	 </tbody>
           </table>
     </div>
  	
  	<table border="1" id="channelTable" class="table_02" style="height:150px">
  		<tr height="50px">
  			<td colspan="2" align="center">
  				 合作伙伴代码：&nbsp;<input id="channelCodeInput" type="text" value="" class="input_text" />&nbsp;&nbsp;
  				 合作伙伴名称：&nbsp;<input id="channelNameInput" type="text" value="" class="input_text" />&nbsp;&nbsp;
				 <input type="button" id="searchButton" class="input_button_1"  value="查询" onclick="queryChannelInfo(1)"/>
				<span style="color: blue;font-weight: bold;font-size: 16px">本页面只支持编辑功能&nbsp;</span> 
			</td>
  		</tr>
  		<tr>
  			<td valign="top">
	  			<div id="channelInfoDIV" style="width:98%;margin:5px" >
			  		<table class="table_02" id="channelInfoTable">
			  		<thead>
		              <tr>
		                  <th style="width:10%">合作伙伴代码</th>
		                  <th style="width:25%">合作伙伴名称</th>
		                  <th style="width:10%">合作伙伴分类</th>
		                  <th style="width:25%">所属机构</th>
		                  <th style="width:15%">合作方式</th>
		                  <th style="width:15%">操作</th>
		              </tr>
		              </thead>
		            </table>
	  				 <div id="channelInfoPageDIV"  class="page"></div>
	  			</div>
  			</td>
  		</tr>
  	</table>
  	
  	<%--添加或修改ChanelAttribute相关数据弹出层 --%>
	<div id="editChanelAttributeDiv"  style="display:none;overflow-y:auto; width:65%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeSaveOrUpdateDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr>
					                  <td width="30%" style="text-align:right;border-right:0px;">合作伙伴代码：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input type="text" id="channelCode" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:450px;"></td>
					                </tr>
					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">合作伙伴名称：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="channelName" type="text" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:450px;"></td>
					                </tr>
					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">合作伙伴分类：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="channelSort" type="text" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:450px;"></td>
					                </tr>
 					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">所属机构：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="deptCname" type="text" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:450px;"></td>
					                </tr>
 					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">所属机构代码：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="deptCode" type="text" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:450px;"></td>
					                </tr>
					                <tr id = "payBackURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">支付结果回调地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="payBackURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
					                <tr id = "uwBackURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">核保结果回调地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="uwBackURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
					                <tr id = "einvoiceBackURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">电子发票回调地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="einvoiceBackURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
					                <tr id = "corrBackURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">新意健险批改回写地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="corrBackURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
					                <tr id = "ncorrBackURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">财险批改回写地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="ncorrBackURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
					                <tr id = "physicalExaminationDeptTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">体检机构：&nbsp;</td>
					                  <td width="70%" style="text-align:left">
					                  		<select id="physicalExaminationDept" name='physicalExaminationDept' class='select_1'style='visibility: visible;width:125px;'>
												<option value=''>-----请选择-----</option>
												<option value='SZ'>善诊</option>
												<option value='YHT'>通用体检机构</option>
											</select>
					                  </td>
					                <tr id = "afferentPolnoTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">是否接口传入保单号：&nbsp;</td>
					                  <td width="70%" style="text-align:left">
					                  		<select id="afferentPolno" name='afferentPolno' class='select_1'style='visibility: visible;width:125px;'>
												<option value=''>-----请选择-----</option>
												<option value='0'>否</option>
												<option value='1'>是</option>
											</select>
					                  </td>
					                </tr>
					                <tr id = "physicalExaminationURLTr">  
					                  <td width="30%" style="text-align:right;border-right:0px;">体检机构地址：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="physicalExaminationURL" type="text" class="input_text" style="width:450px;"></td>
					                </tr>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveOrUpdateChannelAttribute('update')" value="保存"/>&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeSaveOrUpdateDiv()" value="取消"/>
			</div>
	</div>
  	
  </body>
</html>
